/* 封装axios的http请求函数*/
import axios from 'axios';
import qs from 'qs';

class HTTP {
  axiosPost(options) {
    axios({
      url: options.url,
      method: 'post',
      withCredentials: true, //带着cookie的资质，说明我要携带cookie
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: qs.stringify(options.data) //把data对象转查询字符串序列化
    }).then(res => {
      options.success(res.data);
    }).catch(err => {
      options.error(err);
    })
  }

  axiosGet (options) {
    axios({
      url: options.url,
      method: 'get',
      withCredentials: true, //带着cookie的资质，说明我要携带cookie
    }).then(res => {
      options.success(res.data);
    }).catch(err => {
      options.error(err);
    })
  }
}

export default HTTP;


